package demo.ybt;

public class P1264_2 {
    public static void main(String[] args) {
        P1264_2 p1264_2 = new P1264_2();
        int res = p1264_2.res(new int[]{186, 186, 150, 200, 160, 130, 197, 220});
        System.out.println(res);
    }
    public int res(int[] t) {

        //dp1记录最长子序列    从左到右
        //dp2记录最长子序列    从右到左

        int dp1[] = new int[t.length];
        int dp2[] = new int[t.length];

        for (int i = 0; i < t.length; i++) {
            //dp1[i]
            dp1[i] = 1;
            for (int j = 0; j < i; j++) {
                if (t[j] < t[i]) {
                    dp1[i] = Math.max(dp1[j] + 1, dp1[i]);
                }
            }
        }

        int max = 1;
        for (int i = t.length - 1; i >= 0; i--) {
            dp2[i] = 1;
            for (int j = t.length - 1; j > i ; j--) {
                if (t[j] < t[i]) {
                    dp2[i] = Math.max(dp2[i], dp2[j] + 1);
                    max = Math.max(dp1[i] + dp2[i] - 1, max);
                }
            }
        }
        return max;
    }
}
